package com.newer.his.common.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.newer.his.common.entity.Medicine;
// 字段:drug_id, dname, price, unit, useage, type, inventory
@Mapper
public interface MedicineMapper {
	@Options(useGeneratedKeys = true, 
			keyColumn = "drug_id", 
			keyProperty = "id")
	
	@Insert("insert into medicine(dname, price, unit, useage, type, inventory)"
			+ " values(#{dname},#{price},#{unit},#{useage},#{type},#{inventory})")
	void save (Medicine medicine);
	
	
	@Select("select drug_id, dname, price, unit, useage, type, inventory"
			+ " from medicine where drug_id=#{id}")
	Medicine findById(int id);
	
	@Select("select drug_id, dname, price, unit, useage, type, inventory"
			+ " from medicine")
	List<Medicine> findAll();
	
	
	@Update("update medicine set  dname=#{dname}, price=#{price},"
			+ " unit=#{unit}, useage=#{useage}, type=#{type}, inventory=#{inventory}"
			+ " where drug_id=#{id}")
	void update(Medicine medicine);
	
	
	@Delete("delete from medicine where drug_id=#{id}")
	void delete(int id);
	

}
